<template>
  <span>{{ info.name }}</span>
  <button @click="btnClick2">点击改变info.name</button>
</template>

<script>
export default {
  name: 'HelloWorld',
  data() {
    return {
      info: {
        name: 'zjd',
        age: 19,
      },
    }
  },
  watch: {
    'info.name': function (newV, oldV) {
      console.log(newV, oldV, 1111)
    },
  },
  methods: {
    btnClick2() {
      this.info.name = 'hq'
      this.info.age = Math.random() + '22'
    },
  },
  created() {
    const unWatch = this.$watch('info.age', function (newAge, oldAge) {
      console.log(newAge, oldAge, 2222)
    })
    // 取消监听
    // unWatch()
  },
}
</script>
<style scoped></style>
